$(function () {
    sortSelFn();
    checkInfoFn();

    initYearFilter();

    $("body").on('click','#filter-order>li',function () {
        $('#filter-order>li').removeClass('active');
        $(this).addClass('active');
        var status = $(this).data('status');
        $("#status").val(status);
        closeFilterPanel();
        ajaxFindUserCashRecordList(1);
    }).on('click', '#filter-clean', function () { // 清空筛选
        cleanFilter();
    }).on('click', '#filter-year li', function () { //年份筛选
        if ($(this).hasClass('active')) return;
        activeFilterCondition(this);
        $('#createTime').val($(this).data('year'));

    }).on('click', '#filter-ensure', function () { // 确定筛选
        $('#page-infinite-scroll-bottom').unbind();
        closeFilterPanel();
        ajaxFindUserCashRecordList(1);
    });

    //执行获取数据
    ajaxFindUserCashRecordList(1);

    /**
     * 加载账号变动记录
     * @param pageNo
     */
    function ajaxFindUserCashRecordList(pageNo) {
        var status = $("#status").val();
        var createTime = $("#createTime").val();
        var _params= {};
        _params.status = status;
        _params.year = createTime;
        var obj={
            url: baseloaction + '/mobile/uc/cash/ajaxFindUserCashRecordList',//请求url
            contextId:'withdraw-record-list-box',//请求成功后数据内容添加的地方
            pageNo:pageNo,//页面码，可以不传
            pageCall:ajaxFindUserCashRecordList,//分页方法（一般调用自身）
            params:JSON.stringify(_params),//查询参数
            callback:function (pageNo) {
                var dataList = $("div[data-year]");
                if(dataList.length > 0){
                    $(".div-year-box").remove();
                    var tagEm = $(dataList[0]);
                    var year = tagEm.data('year');
                    $('<div class="card-header div-year-box"><strong class="fs7">'+year+'年</strong></div>').insertBefore(tagEm);
                    dataList.each(function (index,em) {
                        if(tagEm.data('year') !=$(em).data('year')){
                            year = $(em).data('year');
                            $('<div class="card-header div-year-box"><strong class="fs7">'+year+'年</strong></div>').insertBefore($(em));
                        }
                        tagEm = $(em);
                    });
                }
            }
        }
        loadMobilePathData(obj);
    }
});

// 年筛选器
function initYearFilter() {
    var now = new Date().getYear() + 1900;
    for (var year = 2016; year <= now ; year++) {
        $('#filter-year').append('<li class="col-25" data-year="' + year + '">' +
            '<a href="javascript:void(0)" class="button button-round">' + year + '</a>' +
            '</li>');
    }
}

// 分类筛选
function sortSelFn() {
    var bEle = $('.wm-cl__wrap');
    $('.wm-buttons-select-tab__wrap').on('click', '.tab-link', function () {
        if($(this).hasClass('active')){
            if(bEle.hasClass('sortSeOpen')){
                bEle.removeClass('sortSeOpen');
            }else {
                bEle.addClass('sortSeOpen');
            }
        }else {
            activeFilterCondition(this);
            bEle.addClass('sortSeOpen');
        }
    });
    $('.modal-overlay').on('click', function () {
        if (bEle.hasClass('sortSeOpen')){
            bEle.removeClass('sortSeOpen');
        }
    });
}
// 专业 课程类型 排序筛选器
function activeFilterCondition(obj) {
    $(obj).addClass('active').siblings().removeClass('active');
}

// 关闭筛选面板
function closeFilterPanel() {
    $('.wm-cl__wrap').removeClass('sortSeOpen')
}

// 清空筛选
function cleanFilter() {
    $('#filter-year').each(function () {
        $(this).children().eq(0).addClass('active').siblings().removeClass('active');
        $("#createTime").val("");
    });
}

// 查看详情
var checkInfoFn = function () {

    $(document).on('click', '.checkInfoBtn', function () {
        var rejectText = $(this).data('text');
        var _ele = '<div class="pr pt5 pb5">';
        _ele +='<aside class="exam-stop-icon checkInfo-icon"><span>&nbsp;</span></aside>';
        _ele +='<section class="text-center">';
        _ele +='<h3 class="" style="margin-bottom: 0;font-weight: 200;">查看明细</h3>';
        _ele +='<span class="fs6 c-888">您本次提现申请未通过运营审核，原因如下：</span>';
        _ele +='</section>';
        _ele +='<section class="mt5">';
        _ele +=' <span class="fs6 c-333">rejectText</span>';
        _ele +='</section>';
        _ele +='</div>';
        $.alert(_ele);
        $('.modal-in').find('.modal-button-bold').text('知道了').attr('style', '');
    })
}